package org.dragonnova.meetingapp.app.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import org.dragonnova.meetingapp.R;
import org.dragonnova.meetingapp.model.bean.MeetingInfo;

import java.util.List;

/**
 * Created by hucn on 2016/5/11.
 * Description:查找设备的界面
 */

public class MeetingAdapter extends BaseAdapter {

    private Context mContext;
    private List<MeetingInfo> deviceList;

    public MeetingAdapter(Context context, List<MeetingInfo> deviceList) {
        this.deviceList = deviceList;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return deviceList.size();
    }

    @Override
    public Object getItem(int position) {
        return deviceList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_history, null);
            holder = new Holder();
            holder.history_tv_name = (TextView) convertView.findViewById(R.id.history_tv_name);
            holder.history_iv_name = (ImageView) convertView.findViewById(R.id.history_iv_name);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        MeetingInfo meetingInfo = deviceList.get(position);
        holder.history_tv_name.setText(meetingInfo.getName());
        if (meetingInfo.getFlag() == 2){
            holder.history_iv_name.setImageResource(R.drawable.collection_on);
        }else{
            holder.history_iv_name.setImageResource(R.drawable.collection_off);
        }
        //holder.history_iv_name.

        return convertView;
    }

    public static class Holder {
        private TextView history_tv_name;
        private ImageView history_iv_name;
    }
}